package net.dgg.dggcloud.service.jrcrm.service.orf;

import net.dgg.dggcloud.core.minidao.hibernate.dao.IGenericBaseCommonDao;
import net.dgg.dggcloud.service.common.base.service.BaseService;
import net.dgg.dggcloud.service.entity.user.User;
import net.dgg.dggcloud.service.jrcrm.dao.orf.PerformanceDao;
import net.dgg.dggcloud.service.jrcrm.entity.orf.PerformancePrefit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 财务 业绩
 *
 * @author 郭伟 2017/11/2
 */
@Service
public class PerformanceService extends BaseService {

    @Autowired
    private PerformanceDao performanceDao;



    @Resource(name="miniDaoHiberCommonDao")
    protected IGenericBaseCommonDao repository;

    /**
     *   根据商机ID，客户ID，查询相应的业绩和利润
     * @param map
     *  customerId 客户ID
     *  businessId 商机ID
     * @return
     */
    public Map listPerformanceMap(Map map) {
        Map resultMap = new HashMap();
        List<Map> mapList = performanceDao.listPerformanceMap(map);
        Map map1 = performanceDao.performanceMap(map);
        resultMap.put("list",mapList); //业绩详情
        resultMap.put("achievementTotal",map1.get("achievementTotal"));   //总业绩
        resultMap.put("profitTotal",map1.get("profitTotal")); //总利润
        resultMap.put("assistAchievementTotal",map1.get("assistAchievementTotal")); //总协单业绩
        resultMap.put("assistProfitTotal",map1.get("assistProfitTotal")); //总协单利润
        return resultMap;
    }


    /**
     *   根据
     * @param map
     *  type 成本类型 1 退款 ，2 核款
     *  paymentId 财务ID
     * @return
     */
    public List<Map> getPerformanceMap(Map map) {
        return performanceDao.getPerformanceMap(map);
    }

    /**
     * 通过订单id统计财务核款信息
     * @param orderId
     * @return
     */
    public List<Map> queryTotoalOfOrderBYOrderId(long orderId) {
        Map map=new HashMap();
        map.put("orderId",orderId);
        return performanceDao.queryTotoalOfOrderByMap(map);
    }

    /**
     *  通过子订单ID，统计相关业绩分配信息
     *  orderBusinessId
     * @return
     */
    public List<Map> getPerformanceSum(Map map){
        return performanceDao.getPerformanceSum(map);
    };

    /**
     *  通过子订单ID，统计相关业绩分配信息
     *  orderBusinessId
     *  paymentId 财务ID
     * @return
     */
    public List<Map> getUpdateReimbursePerformanceSum(Map map){
        return performanceDao.getUpdateReimbursePerformanceSum(map);
    };



    /**
     *  通过用户ID查询该人员业绩，管理者查询下面人员业绩
     *  Map userId
     * @return
     */
    public Long getUserOrgPerformance(Map map){
        return performanceDao.getUserOrgPerformance(map);
    };


    /**
     *  通过用户ID查询该人员业绩，管理者查询下面人员业绩 TOP5
     *  Map
     * @return
     */
    public List<Map> workPerformanceTeamTop5(Map map){
        return performanceDao.workPerformanceTeamTop5(map);
    };


    public Long performanceTeamSum(Map map){
        return performanceDao.performanceTeamSum(map);
    }




}
